﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.Objects;
using System.Data;
using System.Data.Common;
using System.Data.Entity;
using System.Threading;
using System.Transactions;
using System.Data.SqlClient;
using System.Configuration;
using System.Timers;
using MINERP.DAL;
using MINERP.DAL.DigitalOutput;
using MINERP.COM;
using MINERP.DAL.CommonDAL;
using Leadtools;
using Leadtools.Codecs;
using Timer = System.Timers.Timer;

namespace MINERP.BLL.DigitalOutput
{
    public class DigitalOutputBLL
    {
        public DigitalOutputBLL()
        {
            timeDistribute.Enabled = false;
            timeDistribute.Interval = 60000;//一分钟
            timeDistribute.Elapsed += new ElapsedEventHandler(timeDistribute_Elapsed);
           
        }
        public delegate void ShowMessage(DataTable  table, int disCount);
        
        
        DigitalOutPutDAL DDAL = new DigitalOutPutDAL();
        BLL.Common.WorkFlowListBLL WBLL = new MINERP.BLL.Common.WorkFlowListBLL();
        
        #region 创建照片结构
        /// <summary>创建照片结构
        /// 创建照片结构
        /// </summary>
        public DataTable CreatePhotoDT()
        {
            DataTable dt = new DataTable();
            dt.Columns.Add(new DataColumn("PhotoID", typeof(int)));
            dt.Columns.Add(new DataColumn("PhotoBarCode", typeof(string)));
            dt.Columns.Add(new DataColumn("PrinterId", typeof(int)));                   //打印机Id,预分配打印机使用
            dt.Columns.Add(new DataColumn("PaperTypeName", typeof(string)));
            dt.Columns.Add(new DataColumn("PaperFaceName", typeof(string)));
            dt.Columns.Add(new DataColumn("ShopName", typeof(string)));
            dt.Columns.Add(new DataColumn("CtmName", typeof(string)));
            dt.Columns.Add(new DataColumn("PhotoSize", typeof(string)));
            dt.Columns.Add(new DataColumn("PhotoSize1", typeof(string)));
            dt.Columns.Add(new DataColumn("PhotoDPI", typeof(int)));
            dt.Columns.Add(new DataColumn("OrderBagID", typeof(int)));
            dt.Columns.Add(new DataColumn("OrderBarCode", typeof(string)));
            dt.Columns.Add(new DataColumn("OrderName", typeof(string)));
            dt.Columns.Add(new DataColumn("OrderPriority", typeof(int)));               //加急级别
            dt.Columns.Add(new DataColumn("OrderProductID", typeof(int)));              //订单产品ID
            dt.Columns.Add(new DataColumn("OrderProductCode", typeof(string)));
            dt.Columns.Add(new DataColumn("OrderProductType", typeof(int)));            //产品类型(status中的OrderBagType)
            dt.Columns.Add(new DataColumn("OrderProductName", typeof(string)));
            dt.Columns.Add(new DataColumn("Area", typeof(string)));//地区
            dt.Columns.Add(new DataColumn("OrderTime", typeof(DateTime)));
            dt.Columns.Add(new DataColumn("FetchTime", typeof(DateTime)));
            dt.Columns.Add(new DataColumn("Remark", typeof(string)));
            dt.Columns.Add(new DataColumn("PhotoAreas", typeof(decimal)));
            dt.Columns.Add(new DataColumn("ProductName", typeof(string)));
            return dt;
        }
        #endregion

        #region 获取照片信息集合
        /// <summary>获取照片信息集合
        /// 获取照片信息集合
        /// </summary>
        public DataTable GetPhotoList(bool IsDistributed, int techId, int printerId,out List<string> ErrList)
        {
            ErrList=new List<string>();
            try
            {
                //1
                int status = 0;
                if (IsDistributed)
                    status = (int)PhotoStatus.DistributedPrinter;       //已分配
                else
                    status = (int)PhotoStatus.NoDistributePrinter;      //未分配
                int usingStatus = (int)OrderFlowListStatus.Useable;
                int usingStatus2 = (int)OrderFlowListStatus.UseableAccept;
                int orderInfoStop = (int)OrderInfoStatus.Stop;          //产品已停止
                int orderBagDel = (int)OrderBagStatus.Deleted;          //订单已删除
                int orderinfoDel = (int)OrderInfoStatus.Deleted;
                DataTable query;
                if (IsDistributed)                                      //已分配
                {
                    query = DDAL.GetPhotoListForChange(status, printerId, orderInfoStop, orderBagDel, orderinfoDel);
                }
                else                                                    //未分配
                {
                    query = DDAL.GetPhotoList(status, techId, usingStatus, usingStatus2);
                }
                DataTable photoDT = CreatePhotoDT();
                foreach (DataRow record in query.Rows)
                {
                    DataRow r = photoDT.NewRow();
                    r["PhotoID"] = record["PhotoID"];
                    r["PhotoBarCode"] = record["PhotoBarCode"];
                    r["PrinterId"] = record["PrinterId"];
                    r["PaperTypeName"] = record["PaperTypeName"];
                    r["PaperFaceName"] = record["PaperFaceName"];
                    r["ShopName"] = record["ShopName"];
                    r["CtmName"] = record["CtmName"];
                    double width = Convert.ToDouble(record["SizeWidth"]);
                    double height = Convert.ToDouble(record["SizeHeight"]);
                    r["PhotoSize"] = string.Format("{0:.##}", width) + "×" + string.Format("{0:.##}", height);
                    r["Remark"] = r["PhotoBarCode"] = record["Remark"];
                    r["PhotoSize1"] = string.Format("{0:.##}", width*2.54) + "×" + string.Format("{0:.##}", height*2.54);
                    int pixWidth = Convert.ToInt32(record["PixWidth"]);
                    int pixHeight = Convert.ToInt32(record["PixHeight"]);
                    if(pixWidth==0||width==0)
                    {
                        ErrList.Add("("+record["OrderProductId"]+","+record["PhotoBarCode"]+")");
                        continue;
                    }
                    int photoDPI = Convert.ToInt32(pixWidth / width);

                    r["PhotoDPI"] = photoDPI;
                    r["OrderBarCode"] = record["OrderBagCode"];
                    r["OrderProductCode"] = record["OrderProductCode"];
                    r["OrderTime"] = record["OrderTime"];
                    r["FetchTime"] = record["FetchTime"];
                    r["OrderBagID"] = record["OrderBagID"];
                    r["OrderName"] = record["OrderName"];
                    r["OrderPriority"] = record["OrderPriority"];
                    r["OrderProductId"] = record["OrderProductId"];
                    r["OrderProductName"] = record["OrderProductName"];
                    r["OrderProductType"] = record["ProductType"];              //产品类型
                    r["Area"] = record["Area"];
                    r["PhotoAreas"] = width * 2.54 * height * 2.54 / 10000;
                    int index=record["OrderProductName"].ToString().IndexOf('_');
                    if (index > 0)
                    {
                        r["ProductName"] = record["OrderProductName"].ToString().Substring(index+1);
                    }
                   
                    photoDT.Rows.Add(r);
                }
                return photoDT;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        #endregion

        #region 获取照片信息集合(更新时使用)
        /// <summary>
        /// 获取照片信息集合(更新时使用)
        /// </summary>
        public ObjectQuery<photoInfo> GetPhotoListForUpdate(int techId)
        {
            try
            {
                //将照片信息列表保存起来,在更新照片时使用
                int usingStatus = (int)OrderFlowListStatus.Useable;
                int usingStatus2 = (int)OrderFlowListStatus.UseableAccept;
                ObjectQuery<photoInfo> tb_PhotoList = DDAL.GetPhotoListForUpdate((int)PhotoStatus.NoDistributePrinter, techId, usingStatus, usingStatus2);
                return tb_PhotoList;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        #endregion

        #region 获取打印机信息
        /// <summary>
        /// 获取打印机信息
        /// </summary>
        public List<STPrinter> GetPrinterInfo()
        {
            try
            {
                List<STPrinter> printerInfo = new List<STPrinter>();
                /*
                List<printer> query = DDAL.GetPrinterInfo();
                foreach (printer record in query)
                {
                    STPrinter st = new STPrinter();
                    st.PrinterID = record.PrinterID;
                    st.PrinterName = record.PName;
                    st.PrinterType = record.PType;
                    st.PrinterDPI = record.PDPI;
                    st.TaskNum = DDAL.GetTaskNumByPrinterID(st.PrinterID, (int)PhotoStatus.DistributedPrinter);
                    printerInfo.Add(st);
                }*/
                DataTable dt = DDAL.GetPrinterInfo();
                foreach (DataRow record in dt.Rows)
                {
                    STPrinter st = new STPrinter();
                    st.PrinterID = Convert.ToInt32(record["PrinterID"]);
                    st.PrinterName = record["PrinterName"].ToString();
                    st.PrinterType = record["PrinterType"].ToString();
                    st.PrinterDPI = Convert.ToInt32(record["PrinterDPI"]);
                    st.PrinterLength = Convert.ToDouble(record["PLength"]);
                    st.PrinterWidth = Convert.ToDouble(record["PWidth"]);
                    if (record["Speed"] == DBNull.Value)
                        st.Speed = 0;
                    else
                        st.Speed = Convert.ToDouble(record["Speed"]);
                    st.IsDisable = Convert.ToBoolean(record["IsDisable"]);
                    st.TaskNum = DDAL.GetTaskNumByPrinterID(st.PrinterID, (int)PhotoStatus.DistributedPrinter, (int)PhotoStatus.PingBanInd);
                    printerInfo.Add(st);
                }
                return printerInfo;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        /// <summary>
        /// 获取打印机的信息
        /// </summary>
        /// <param name="PrinterID"></param>
        /// <returns></returns>
        public STPrinter GetPrinter(int PrinterID)
        {
            STPrinter rtnPrinter = new STPrinter();
            using (newSampleYPDBEntities db = new newSampleYPDBEntities())
            {
                printer p = db.printer.FirstOrDefault(pt=>pt.PrinterID==PrinterID);
                rtnPrinter.PrinterID = p.PrinterID;
                rtnPrinter.PrinterDPI = p.PDPI;
            }
            return rtnPrinter;
        }
        #endregion

        #region 获取打印机已分配的照片数量
        /// <summary>
        /// 获取打印机已分配的照片数量
        /// </summary>
        public int GetTaskNumByPrinterID(int printerID)
        {
            try
            {
                return DDAL.GetTaskNumByPrinterID(printerID, (int)PhotoStatus.DistributedPrinter, (int)PhotoStatus.PingBanInd);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        #endregion

        /*
        #region 为照片分配打印机
        /// <summary>
        /// 为照片分配打印机,返回分配的照片数量(可能有重复的照片，所以需要计算)
        /// </summary>
        public int SetPrinterForPhoto(List<STDistributePhoto> distributePhotos, int techId)
        {
            try
            {
                int photoNum = 0;
                List<photoInfo> InsertRepeatPhoto = new List<photoInfo>();
                ObjectQuery<photoInfo> tb_PhotoList = GetPhotoListForUpdate(techId);
                foreach (STDistributePhoto _distributePhoto in distributePhotos)
                {
                    //更新照片状态,分配打印机
                    foreach (photoInfo photo in tb_PhotoList)
                    {
                        if (photo.photoId == _distributePhoto.PhotoID)
                        {
                            photo.status = _distributePhoto.Status;
                            photo.printerId = _distributePhoto.PrinterID;
                            //插入重复的照片(产品数量减1)
                            int insertNum = photo.orderInfo.productNum - 1;
                            photoNum += insertNum + 1;
                            for (int i = 0; i < insertNum; i++)
                            {
                                photoInfo newPhoto = new photoInfo();
                                newPhoto.Height = photo.Height;
                                newPhoto.IsModifySize = photo.IsModifySize;
                                newPhoto.MakeUpNum = photo.MakeUpNum;
                                newPhoto.OldPicPath = photo.OldPicPath;
                                newPhoto.orderInfo = photo.orderInfo;
                                newPhoto.paperFace = photo.paperFace;
                                newPhoto.paperType = photo.paperType;
                                newPhoto.PhotoBarCode = "3333333333";
                                newPhoto.photoName = photo.photoName;
                                newPhoto.picPath = photo.picPath;
                                newPhoto.pixHeight = photo.pixHeight;
                                newPhoto.pixWidth = photo.pixWidth;
                                newPhoto.printerId = photo.printerId;
                                newPhoto.Remark = photo.Remark;
                                newPhoto.status = photo.status;
                                newPhoto.TotalNum = photo.TotalNum;
                                newPhoto.Width = photo.Width;
                                InsertRepeatPhoto.Add(newPhoto);
                            }
                            break;
                        }
                    }
                    //将打印机和照片的关系保存进tb
                }
                MINERP.DAL.DigitalOutput.DigitalOutPutDAL.Save();
                //更新照片码
                foreach (photoInfo photo in InsertRepeatPhoto)
                {
                    photo.PhotoBarCode = "3" + string.Format("{0:d9}", Convert.ToInt32(photo.EntityKey.EntityKeyValues[0].Value));
                }
                MINERP.DAL.DigitalOutput.DigitalOutPutDAL.Save();

                
                return photoNum;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        /// <summary>
        /// 按打印机DPI分配打印机
        /// 如果照片DPI不等打印机DPI，需重新计算照片高宽
        /// </summary>
        public int SetPrinterForPhoto2(int printerDPI, List<STDistributePhoto> distributePhotos, int techId)
        {
            try
            {
                int photoNum = 0;
                List<photoInfo> InsertRepeatPhoto = new List<photoInfo>();
                ObjectQuery<photoInfo> tb_PhotoList = GetPhotoListForUpdate(techId);
                foreach (STDistributePhoto _distributePhoto in distributePhotos)
                {
                    //更新照片状态,分配打印机
                    foreach (photoInfo photo in tb_PhotoList)
                    {
                        if (photo.photoId == _distributePhoto.PhotoID)
                        {
                            if (_distributePhoto.PhotoDPI != printerDPI)
                            {
                                photo.Height = photo.pixHeight / (double)printerDPI;
                                photo.Width = photo.pixWidth / (double)printerDPI;
                            }
                            photo.status = _distributePhoto.Status;
                            photo.printerId = _distributePhoto.PrinterID;
                            //插入重复的照片(产品数量减1)
                            int insertNum = photo.orderInfo.productNum - 1;
                            photoNum += insertNum + 1;
                            for (int i = 0; i < insertNum; i++)
                            {
                                photoInfo newPhoto = new photoInfo();
                                newPhoto.Height = photo.Height;
                                newPhoto.IsModifySize = photo.IsModifySize;
                                newPhoto.MakeUpNum = photo.MakeUpNum;
                                newPhoto.OldPicPath = photo.OldPicPath;
                                newPhoto.orderInfo = photo.orderInfo;
                                newPhoto.paperFace = photo.paperFace;
                                newPhoto.paperType = photo.paperType;
                                newPhoto.PhotoBarCode = "3333333333";
                                newPhoto.photoName = photo.photoName;
                                newPhoto.picPath = photo.picPath;
                                newPhoto.pixHeight = photo.pixHeight;
                                newPhoto.pixWidth = photo.pixWidth;
                                newPhoto.printerId = photo.printerId;
                                newPhoto.Remark = photo.Remark;
                                newPhoto.status = photo.status;
                                newPhoto.TotalNum = photo.TotalNum;
                                newPhoto.Width = photo.Width;
                                InsertRepeatPhoto.Add(newPhoto);
                            }
                            break;
                        }
                    }
                    //将打印机和照片的关系保存进tb
                }
                MINERP.DAL.DigitalOutput.DigitalOutPutDAL.Save();
                //更新照片码
                foreach (photoInfo photo in InsertRepeatPhoto)
                {
                    photo.PhotoBarCode = "3" + string.Format("{0:d9}", Convert.ToInt32(photo.EntityKey.EntityKeyValues[0].Value));
                }
                MINERP.DAL.DigitalOutput.DigitalOutPutDAL.Save();
                return photoNum;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }*/

        #region 为单张照片分配打印机，并生成重复的照片，返回总共分配的照片数量(传统模式稳定后删除)
        /// <summary>
        /// 为单张照片分配打印机，并生成重复的照片，返回总共分配的照片数量
        /// </summary>
        /// <param name="pi"></param>
        /// <param name="printerDPI"></param>
        /// <returns></returns>
        //public int DistributeSinglePhoto(MODEL.DigitalModel.STDistributePhoto pi, int printerDPI, int techId, int userId)
        //{
        //    try
        //    {
        //        int photoNum = 0;
        //        System.Transactions.TransactionOptions options = new TransactionOptions();
        //        options.Timeout = new TimeSpan(0, 0, 600);
        //        options.IsolationLevel = System.Transactions.IsolationLevel.ReadUncommitted;
        //        using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required, options))
        //        {
        //            photoInfo photo = PhotoInfoDAL.GetOneById(pi.PhotoID);
        //            //检查DPI，大小
        //            if (pi.DistributeType == true && pi.PhotoDPI != printerDPI)   //按打印机DPI分配，并且照片DPI不等于打印机DPI(高宽小数点后只保留一位)
        //            {
        //                photo.Height = (double)photo.pixHeight / printerDPI;
        //                photo.Width = (double)photo.pixWidth / printerDPI;
        //            }
        //            /*
        //            else if (pi.DistributeType == false && pi.PhotoDPI != printerDPI)   //按照片本身尺寸分配
        //            {
        //                //photo.Height = Math.Round(photo.Height, 1);
        //                //photo.Width = Math.Round(photo.Width, 1);
        //            }
        //            else                                                            //打印机DPI和照片本身DPI相等，但要将照片高宽保留1位小数
        //            {
        //            }*/
        //            photo.pixWidth = Convert.ToInt32(Math.Round(photo.Width + 0.04, 1) * printerDPI);        
        //            photo.pixHeight = Convert.ToInt32(Math.Round(photo.Height + 0.04, 1) * printerDPI);

        //            photo.status = (int)PhotoStatus.DistributedPrinter;
        //            photo.printerId = pi.PrinterID;
        //            //插入重复的照片(产品数量减1)
        //            int insertNum = 0;
        //            List<photoInfo> InsertRepeatPhoto = new List<photoInfo>();
        //            if (photo.status2 != (int)COM.PhotoStatus2.innerReturn)         //如果是返单就不需要复制重复照片
        //            {
        //                if (!photo.orderInfoReference.IsLoaded)
        //                    photo.orderInfoReference.Load();
        //                insertNum = (int)photo.TotalNum * photo.orderInfo.productNum - 1;
        //                photo.TotalNum = 1;
        //                //photoNum += insertNum + 1;
        //                for (int i = 0; i < insertNum; i++)
        //                {
        //                    photoInfo newPhoto = new photoInfo();
        //                    newPhoto.Height = photo.Height;
        //                    newPhoto.IsModifySize = photo.IsModifySize;
        //                    newPhoto.MakeUpNum = photo.MakeUpNum;
        //                    newPhoto.OldPicPath = photo.OldPicPath;
        //                    if (!photo.paperFaceReference.IsLoaded)
        //                        photo.paperFaceReference.Load();
        //                    if (!photo.paperTypeReference.IsLoaded)
        //                        photo.paperTypeReference.Load();
        //                    if (!photo.orderInfoReference.IsLoaded)
        //                        photo.orderInfoReference.Load();
        //                    newPhoto.orderInfo = photo.orderInfo;
        //                    newPhoto.paperFace = photo.paperFace;
        //                    newPhoto.paperType = photo.paperType;
        //                    newPhoto.PhotoBarCode = "3333333333";
        //                    newPhoto.photoName = photo.photoName;
        //                    newPhoto.picPath = photo.picPath;
        //                    newPhoto.pixHeight = photo.pixHeight;
        //                    newPhoto.pixWidth = photo.pixWidth;
        //                    newPhoto.printerId = photo.printerId;
        //                    newPhoto.Remark = photo.Remark;
        //                    newPhoto.status = photo.status;
        //                    newPhoto.TotalNum = 1;
        //                    newPhoto.Width = photo.Width;
        //                    InsertRepeatPhoto.Add(newPhoto);
        //                }
        //            }
        //            MINERP.DAL.DigitalOutput.DigitalOutPutDAL.Save();
        //            //更新照片码
        //            foreach (photoInfo p in InsertRepeatPhoto)
        //            {
        //                p.PhotoBarCode = "3" + string.Format("{0:d9}", Convert.ToInt32(p.EntityKey.EntityKeyValues[0].Value));
        //            }
        //            MINERP.DAL.DigitalOutput.DigitalOutPutDAL.Save();

        //            if (!photo.orderInfoReference.IsLoaded)
        //            {
        //                photo.orderInfoReference.Load();
        //            }
        //            if (!photo.orderInfo.photoInfo.IsLoaded)
        //            {
        //                photo.orderInfo.photoInfo.Load();
        //            }

        //            int noDistributePrinterStatus = (int)PhotoStatus.NoDistributePrinter;

        //            int noDistributeNum = photo.orderInfo.photoInfo.Where(pi1 => pi1.status == noDistributePrinterStatus).Count();
        //            if (noDistributeNum == 0)
        //            {
        //                //调用完成方法
        //                Common.WorkFlowListBLL wbll = new MINERP.BLL.Common.WorkFlowListBLL();
        //                wbll.OverCurTech(techId, userId, photo.orderInfo.OrderProductId);
        //            }
        //            photoNum = insertNum + 1;
        //            scope.Complete();
        //        }
        //        return photoNum;
        //    }
        //    catch (Exception ex)
        //    {
        //        DDAL.RefreshPhotoAndOrderInfo();
        //        throw ex;
        //    }
        //}

        //传统模式(目前已不使用)

        public int DistributeSinglePhoto(MODEL.DigitalModel.STDistributePhoto pi, int printerDPI, int techId, int userId)
        {
            try
            {
                int photoNum = 0;
                using (newSampleYPDBEntities db = new newSampleYPDBEntities())
                {
                    photoInfo photo = db.photoInfo.FirstOrDefault(p => p.photoId == pi.PhotoID);
                    if (photo == null)
                    {
                        return -1;
                    }
                    //检查DPI，大小
                    if (pi.DistributeType == true && pi.PhotoDPI != printerDPI)   //按打印机DPI分配，并且照片DPI不等于打印机DPI(高宽小数点后只保留一位)
                    {
                        photo.Height = (double)photo.pixHeight / printerDPI;
                        photo.Width = (double)photo.pixWidth / printerDPI;
                    }
                    /*
                    else if (pi.DistributeType == false && pi.PhotoDPI != printerDPI)   //按照片本身尺寸分配
                    {
                        //photo.Height = Math.Round(photo.Height, 1);
                        //photo.Width = Math.Round(photo.Width, 1);
                    }
                    else                                                            //打印机DPI和照片本身DPI相等，但要将照片高宽保留1位小数
                    {
                    }*/
                    //photo.pixWidth = Convert.ToInt32(Math.Round(photo.Width + 0.04, 1) * printerDPI);
                    //photo.pixHeight = Convert.ToInt32(Math.Round(photo.Height + 0.04, 1) * printerDPI);
                    photo.pixWidth = Convert.ToInt32(photo.Width * printerDPI);
                    photo.pixHeight = Convert.ToInt32(photo.Height  * printerDPI);

                    photo.status = (int)PhotoStatus.DistributedPrinter;
                    photo.printerId = pi.PrinterID;
                    //插入重复的照片(产品数量减1)
                    int insertNum = 0;
                    List<photoInfo> InsertRepeatPhoto = new List<photoInfo>();
                    if (photo.status2 != (int)COM.PhotoStatus2.innerReturn)         //如果是返单就不需要复制重复照片
                    {
                        ///不单单复制照片要连产品一起复制
                        if (!photo.orderInfoReference.IsLoaded)
                            photo.orderInfoReference.Load();
                        insertNum = (int)photo.TotalNum * photo.orderInfo.productNum - 1;
                        photo.TotalNum = 1;

                        for (int i = 0; i < insertNum; i++)
                        {
                            photoInfo newPhoto = new photoInfo();
                            newPhoto.Height = photo.Height;
                            newPhoto.IsModifySize = photo.IsModifySize;
                            newPhoto.MakeUpNum = photo.MakeUpNum;
                            newPhoto.OldPicPath = photo.OldPicPath;
                            if (!photo.paperFaceReference.IsLoaded)
                                photo.paperFaceReference.Load();
                            if (!photo.paperTypeReference.IsLoaded)
                                photo.paperTypeReference.Load();
                            if (!photo.orderInfoReference.IsLoaded)
                                photo.orderInfoReference.Load();
                            newPhoto.orderInfo = photo.orderInfo;
                            newPhoto.paperFace = photo.paperFace;
                            newPhoto.paperType = photo.paperType;
                            newPhoto.PhotoBarCode = "3333333333";
                            newPhoto.photoName = photo.photoName;
                            newPhoto.picPath = photo.picPath;
                            newPhoto.pixHeight = photo.pixHeight;
                            newPhoto.pixWidth = photo.pixWidth;
                            newPhoto.printerId = photo.printerId;
                            newPhoto.Remark = photo.Remark;
                            newPhoto.status = photo.status;
                            newPhoto.TotalNum = 1;
                            newPhoto.Width = photo.Width;
                            InsertRepeatPhoto.Add(newPhoto);
                        }
                    }
                    db.SaveChanges();
                    //更新照片码
                    foreach (photoInfo p in InsertRepeatPhoto)
                    {
                        p.PhotoBarCode = "3" + string.Format("{0:d9}", Convert.ToInt32(p.EntityKey.EntityKeyValues[0].Value));
                    }
                    db.SaveChanges();

                    if (!photo.orderInfoReference.IsLoaded)
                    {
                        photo.orderInfoReference.Load();
                    }
                    if (!photo.orderInfo.photoInfo.IsLoaded)
                    {
                        photo.orderInfo.photoInfo.Load();
                    }

                    int noDistributePrinterStatus = (int)PhotoStatus.NoDistributePrinter;

                    int noDistributeNum = photo.orderInfo.photoInfo.Where(pi1 => pi1.status == noDistributePrinterStatus).Count();
                    if (noDistributeNum == 0)
                    {
                        //调用完成方法
                        Common.WorkFlowListBLL wbll = new MINERP.BLL.Common.WorkFlowListBLL();
                        wbll.OverCurTech(techId, userId, photo.orderInfo.OrderProductId);
                    }
                    photoNum = insertNum + 1;

                }
                return 1;//表示分配成功

            }
            catch (Exception ex)
            {
                DDAL.RefreshPhotoAndOrderInfo();
                throw ex;
            }
        }

        //public int DistributeSinglePhotoTradition(MODEL.DigitalModel.STDistributePhoto pi, int printerDPI, int techId, int userId)
        //{
        //    try
        //    {
        //        //return DDAL.DistributeSinglePhoto(pi, printerDPI, techId, userId);
        //        SqlConnection con = new SqlConnection();
        //        string conStr = ConfigurationManager.ConnectionStrings["fffff"].ToString();
        //        con.ConnectionString = conStr;
        //        SqlCommand cmd = new SqlCommand();

        //        //参数定义
        //        string checkSql = "select case when status=1 then 1 when status<>1 then 0 end from orderinfo where orderproductid=" + pi.OrderProductID;
        //        string updateSql = "update photoinfo set";                                //update语句
        //        string updateSql2 = "";
        //        string selectSql = "select TotalNum,ProductNum from photoInfo,orderinfo where photoid=" + pi.PhotoID + " and photoinfo.orderproductid=orderinfo.orderproductid";
        //        string selectSql2 = "select * from photoinfo where photoid=" + pi.PhotoID;
        //        //select语句
        //        string insertSql = "insert into photoInfo(OrderProductId,PhotoBarCode,photoName,Height,Width,pixWidth,pixHeight,paperTypeID,paperFaceId,picPath,OldPicPath,Remark,IsModifySize,printerId,status,TotalNum,MakeUpNum)";
        //        //insert语句(插入重复的照片)
        //        int insertNum = 0;                                                  //重复的照片数量
        //        MODEL.DigitalModel.PhotoInfoSame photo = new MINERP.MODEL.DigitalModel.PhotoInfoSame();   //要分配的照片

        //        try
        //        {
        //            SqlTransaction tran;
        //            cmd.Connection = con;
        //            con.Open();
        //            tran = con.BeginTransaction();
        //            try
        //            {
        //                cmd.Connection = con;
        //                cmd.Transaction = tran;

        //                //检查产品是否处于可执行状态(orderInfo.Status=1)
        //                cmd.CommandText = checkSql;
        //                int canDo = Convert.ToInt32(cmd.ExecuteScalar());
        //                if (canDo == 0)
        //                {
        //                    tran.Commit();
        //                    return 0;
        //                }

        //                if (pi.PhotoDPI != printerDPI && pi.DistributeType == true)         //按打印机DPI分配，并且照片DPI不等于打印机DPI
        //                {
        //                    updateSql += " Height=round(cast(pixHeight as decimal)/" + printerDPI + ",1),Width=round(cast(pixWidth as decimal)/" + printerDPI + ",1),pixHeight=cast(round(round(cast(pixHeight as decimal)/" + printerDPI + ",1)*" + printerDPI + ",0) as int),pixWidth=cast(round(round(cast(pixWidth as decimal)/" + printerDPI + ",1)*" + printerDPI + ",0) as int),";
        //                }
        //                else if (pi.PhotoDPI != printerDPI && pi.DistributeType == false)   //按照片本身尺寸分配
        //                {
        //                    updateSql += " Height=" + pi.Height + ",Width=" + pi.Width + ",pixHeight=cast(round(" + pi.Height * printerDPI + ",0) as int),pixWidth=cast(round(" + pi.Width * printerDPI + ",0) as int),";
        //                }
        //                else
        //                {
        //                    updateSql += " Height=" + pi.Height + ",Width=" + pi.Width + ",pixHeight=cast(round(" + pi.Height * pi.PhotoDPI + ",0) as int),pixWidth=cast(round(" + pi.Width * pi.PhotoDPI + ",0) as int),";
        //                }
        //                int distributed = (int)COM.PhotoStatus.DistributedPrinter;
        //                updateSql += " status=" + distributed + ",printerId=" + pi.PrinterID;
        //                updateSql += " where photoid=" + pi.PhotoID;
        //                cmd.CommandText = updateSql;
        //                cmd.ExecuteNonQuery();                      //修改照片本身属性

        //                cmd.CommandText = selectSql;
        //                SqlDataReader reader = cmd.ExecuteReader();
        //                while (reader.Read())
        //                {
        //                    insertNum = Convert.ToInt32(reader["TotalNum"]) * Convert.ToInt32(reader["ProductNum"]) - 1;
        //                }
        //                reader.Close();

        //                updateSql2 = " update photoinfo set totalNum=1 where photoid=" + pi.PhotoID;
        //                cmd.CommandText = updateSql2;
        //                cmd.ExecuteNonQuery();

        //                if (insertNum > 0)                          //插入重复照片
        //                {
        //                    cmd.CommandText = selectSql2;
        //                    reader = cmd.ExecuteReader();
        //                    while (reader.Read())
        //                    {
        //                        photo.Height = Convert.ToDouble(reader["Height"]);
        //                        photo.Width = Convert.ToDouble(reader["Width"]);
        //                        photo.IsModifySize = Convert.ToInt16(reader["IsModifySize"]);
        //                        if (reader["MakeUpNum"] != DBNull.Value)
        //                            photo.MakeUpNum = Convert.ToInt32(reader["MakeUpNum"]);
        //                        photo.OldPicPath = reader["OldPicPath"].ToString();
        //                        photo.OrderProductId = Convert.ToInt32(reader["OrderProductId"]);
        //                        photo.PaperFaceId = Convert.ToInt32(reader["PaperFaceId"]);
        //                        photo.PaperTypeID = Convert.ToInt32(reader["PaperTypeID"]);
        //                        photo.PhotoBarCode = reader["PhotoBarCode"].ToString();
        //                        photo.PhotoId = Convert.ToInt32(reader["PhotoId"]);
        //                        photo.photoName = reader["photoName"].ToString();
        //                        photo.PicPath = reader["PicPath"].ToString();
        //                        photo.PixHeight = Convert.ToInt32(reader["PixHeight"]);
        //                        photo.PixWidth = Convert.ToInt32(reader["PixWidth"]);
        //                        photo.PrinterId = Convert.ToInt32(reader["PrinterId"]);
        //                        photo.Remark = reader["Remark"].ToString();
        //                        photo.Status = Convert.ToInt32(reader["Status"]);
        //                        photo.TotalNum = Convert.ToInt32(reader["TotalNum"]);
        //                        //photo.UserId=Convert.ToInt32(reader["UserId"]);
        //                    }
        //                    reader.Close();

        //                    //重复照片
        //                    for (int i = 0; i < insertNum; i++)
        //                    {
        //                        string insertSql2 = "";
        //                        insertSql2 = insertSql + " values(" + pi.OrderProductID + ",'3333333333','" + photo.photoName + "'," + photo.Height + "," + photo.Width + "," + photo.PixWidth + "," + photo.PixHeight + "," + photo.PaperTypeID + "," + photo.PaperFaceId + ",'" + photo.PicPath + "','" + photo.OldPicPath + "','" + photo.Remark + "'," + photo.IsModifySize + "," + photo.PrinterId + "," + photo.Status + "," + photo.TotalNum + "," + photo.MakeUpNum + ")";
        //                        cmd.CommandText = insertSql2;
        //                        cmd.ExecuteNonQuery();

        //                        selectSql = "select @@identity";
        //                        cmd.CommandText = selectSql;
        //                        int currentPhotoId = Convert.ToInt32(cmd.ExecuteScalar());

        //                        string photoBarCode = "3" + string.Format("{0:d9}", currentPhotoId);
        //                        updateSql2 = "update photoInfo set photobarcode='" + photoBarCode + "' where photoid=" + currentPhotoId;
        //                        cmd.CommandText = updateSql2;
        //                        cmd.ExecuteNonQuery();
        //                    }
        //                }

        //                //修改产品流程...
        //                int noDistributed = (int)COM.PhotoStatus.NoDistributePrinter;
        //                string selectSql3 = "select count(photoId) from photoInfo where orderproductid=" + pi.OrderProductID + " and status=" + noDistributed;
        //                cmd.CommandText = selectSql3;
        //                int noDistributedNum = Convert.ToInt32(cmd.ExecuteScalar());
        //                if (noDistributedNum == 0)
        //                {
        //                    Common.WorkFlowListBLL workbll = new MINERP.BLL.Common.WorkFlowListBLL();
        //                    orderInfo currentInfo = DDAL.GetOrderInfo(pi.OrderProductID);
        //                    workbll.OverCurTech(techId, userId, currentInfo.OrderProductId);
        //                }

        //                tran.Commit();
        //                return insertNum + 1;
        //            }
        //            catch (Exception exx)
        //            {
        //                tran.Rollback();
        //                throw exx;
        //            }
        //        }
        //        catch (Exception ex)
        //        {
        //            throw ex;
        //        }
        //    }
        //    catch (Exception e)
        //    {
        //        throw e;
        //    }
        //}

        #endregion

        #region 为照片修改打印机
        public void ChangePrinterDPISingle(MODEL.DigitalModel.STDistributePhoto pi, int printerDPI)
        {
            try
            {
                using (newSampleYPDBEntities db = new newSampleYPDBEntities())
                {

                    //photoInfo photo = PhotoInfoDAL.GetOneById(pi.PhotoID);
                    photoInfo photo = db.photoInfo.Where(p => p.photoId == pi.PhotoID).First();
                    if (pi.DistributeType == true && pi.PhotoDPI != printerDPI)   //按打印机DPI分配，并且照片DPI不等于打印机DPI(高宽小数点后只保留一位)
                    {
                        photo.Height = (double)photo.pixHeight / printerDPI;
                        photo.Width = (double)photo.pixWidth / printerDPI;
                    }/*
                    else if (pi.DistributeType == false && pi.PhotoDPI != printerDPI)   //按照片本身尺寸分配
                    {
                        photo.Height = Math.Round(photo.Height, 1);
                        photo.Width = Math.Round(photo.Width, 1);
                        photo.pixWidth = Convert.ToInt32((photo.Width * printerDPI));
                        photo.pixHeight = Convert.ToInt32((photo.Height * printerDPI));
                    }
                    else                                                            //打印机DPI和照片本身DPI相等，但要将照片高宽保留1位小数
                    {
                        photo.Height = Math.Round(photo.Height, 1);
                        photo.Width = Math.Round(photo.Width, 1);
                        photo.pixWidth = Convert.ToInt32((photo.Width * printerDPI));
                        photo.pixHeight = Convert.ToInt32((photo.Height * printerDPI));
                    }*/
                    photo.pixHeight = Convert.ToInt32(photo.Height  * printerDPI);
                    photo.pixWidth = Convert.ToInt32(photo.Width  * printerDPI);
                    photo.printerId = pi.PrinterID;
                    db.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        /// <summary>
        /// 为照片修改打印机
        /// </summary>
        /// <param name="distributePhotos"></param>
        /// <param name="techId"></param>
        /// <param name="printerId"></param>
        public void ChangePrinterForPhoto(List<MODEL.DigitalModel.STDistributePhoto> distributePhotos, int techId, int srcPrinterId, int tarPrinterId)
        {
            try
            {
                foreach (MODEL.DigitalModel.STDistributePhoto _distributePhoto in distributePhotos)
                {
                    photoInfo photo = DDAL.GetPhotoInfoByPhotoId(_distributePhoto.PhotoID);
                    photo.printerId = tarPrinterId;
                }
                MINERP.DAL.DigitalOutput.DigitalOutPutDAL.Save();
            }
            catch (Exception ex)
            {
                DDAL.RefreshPhoto();
                throw ex;
            }
        }
        #endregion

        #region 修改订单状态
        /// <summary>
        /// 修改订单状态
        /// </summary>
        public void ChangeOrderStatus(int currentTechId, int userId, int orderId)
        {
            try
            {
                //orderInfo order = DDAL.GetOrderInfo(orderId);
                WBLL.OverCurTech(currentTechId, userId, orderId);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        #endregion

        #region 筛选未分配打印机的照片
        /// <summary>
        /// 筛选未分配打印机的照片
        /// </summary>
        public DataTable GetFilterPhotoDT(DataTable srcPhotoDT, string fpaperType, string fpaperFace, string fshopName, string fctmName, string forderBarCode, string forderDetailBarCode, string fPhotoBarCode)
        {
            try
            {
                string strFilter = "";
                if (fpaperType != null && fpaperType.Length > 0)
                {
                    strFilter += " and PaperTypeName like '%" + fpaperType + "%'";
                }
                if (fpaperFace != null && fpaperFace.Length > 0)
                {
                    strFilter += " and PaperFaceName like '%" + fpaperFace + "%'";
                }
                if (fshopName != null && fshopName.Length > 0)
                {
                    strFilter += " and ShopName like '%" + fshopName + "%'";
                }
                if (fctmName != null && fctmName.Length > 0)
                {
                    strFilter += " and CtmName like '%" + fctmName + "%'";
                }
                if (forderBarCode != null && forderBarCode.Length > 0)
                {
                    strFilter += " and OrderBarCode like '%" + forderBarCode + "%'";
                }
                if (forderDetailBarCode != null && forderDetailBarCode.Length > 0)
                {
                    strFilter += " and OrderProductCode like '%" + forderDetailBarCode + "%'";
                }
                if (fPhotoBarCode != null && fPhotoBarCode.Length > 0)
                {
                    strFilter += " and PhotoBarCode like '%" + fPhotoBarCode + "%'";
                }
                if (strFilter.Length == 0)
                    return srcPhotoDT;
                strFilter = strFilter.Substring(4);
                DataRow[] rows = srcPhotoDT.Select(strFilter);
                DataTable filterDT = CreatePhotoDT();
                foreach (DataRow r in rows)
                {
                    DataRow newRow = filterDT.NewRow();
                    newRow.ItemArray = r.ItemArray;
                    filterDT.Rows.Add(newRow);
                }
                return filterDT;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        #endregion

        #region 结构
        #region 打印机结构
        public class STPrinter
        {
            public int PrinterID;
            public string PrinterName;
            public string PrinterType;
            public int PrinterDPI;
            public double PrinterLength;
            public double PrinterWidth;
            public int TaskNum;
            public double Speed;
            public bool IsDisable;
            public double Task;                     //已分配的任务量
            public double AvaluableTask;            //有效的待分配量
        }
        #endregion

        #region 待分配打印机的照片结构
        /// <summary>
        /// 待分配打印机的照片结构
        /// </summary>
        public class STDistributePhoto
        {
            public int PhotoID;
            public string PhotoCode;
            public int Status;
            public int PrinterID;
            public int PhotoDPI;
            public string PaperFace;
            public int OrderProductID;
            /// <summary>
            /// true 按打印机DPI分配； false按照片本身尺寸分配
            /// </summary>
            public bool DistributeType;     //
        }
        #endregion

        #region 订单信息结构
        /// <summary>
        /// 订单信息结构
        /// </summary>
        public class CSOrderInfo
        {
            public int OrderID { get; set; }
            public string OrderBagCode { get; set; }
            public string OrderName { get; set; }
            public string ShopName { get; set; }
            public int OrderPriority { get; set; }
            public DateTime OrderTime { get; set; }
            public DateTime PreCompleteTime { get; set; }
            public string OrderRemark { get; set; }
        }
        #endregion

        #region 商户结构(只包括ID和名称)
        /// <summary>
        /// 商户结构(只包括ID和名称)
        /// </summary>
        public struct STShop
        {
            public int ShopID;
            public string ShopName;
        }
        #endregion

        #region 商户结构(DataTable)
        /// <summary>
        /// 商户结构(DataTable)
        /// </summary>
        /// <returns></returns>
        public DataTable CreateShopDT()
        {
            DataTable dt = new DataTable();
            dt.Columns.Add(new DataColumn("ShopID", typeof(int)));
            dt.Columns.Add(new DataColumn("ShopName", typeof(string)));
            return dt;
        }
        #endregion

        #endregion

        #region 获取纸型集合
        /// <summary>
        /// 获取纸型集合
        /// </summary>
        public List<string> GetPaperType()
        {
            try
            {
                List<string> listPaperType = DDAL.GetPaperType();
                return listPaperType;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        #endregion

        #region 获取纸面集合
        /// <summary>
        /// 获取纸面集合
        /// </summary>
        public List<string> GetPaperFace()
        {
            try
            {
                List<string> listPaperFace = DDAL.GetPaperFace();
                return listPaperFace;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        #endregion

        #region 获取商户集合
        /// <summary>
        /// 获取商户集合
        /// </summary>
        public DataTable GetShop()
        {
            try
            {
                DataTable DTShop = CreateShopDT();
                DataRow row1 = DTShop.NewRow();
                row1["ShopID"] = 0;
                row1["ShopName"] = "全选";
                DTShop.Rows.Add(row1);
                DataTable query = DDAL.GetShop();
                foreach (DataRow record in query.Rows)
                {
                    DataRow row = DTShop.NewRow();
                    row["ShopID"] = record["ShopID"];
                    row["ShopName"] = record["ShopName"];
                    DTShop.Rows.Add(row);
                }
                return DTShop;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        #endregion

        #region 获取指定商户下的客户集合
        /// <summary>
        /// 获取指定商户下的客户集合
        /// </summary>
        public List<string> GetCtmByShopID(int shopID)
        {
            try
            {
                List<string> listCtm = new List<string>();
                ObjectQuery<string> query = DDAL.GetCtmByShopID(shopID);
                foreach (string s in query)
                {
                    listCtm.Add(s);
                }
                return listCtm;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        #endregion

        #region 根据OrderID获取订单信息
        /// <summary>
        /// 根据OrderID获取订单信息
        /// </summary>
        /// <param name="OrderId"></param>
        /// <returns></returns>
        public CSOrderInfo GetOrderInfoByOrderId(int OrderId)
        {
            try
            {
                Tb_OrderBag order = DDAL.GetOrderInfoByOrderId(OrderId);
                CSOrderInfo orderInfo = new CSOrderInfo();
                if (order != null)
                {
                    orderInfo.OrderBagCode = order.BagCode;
                    orderInfo.OrderID = order.OrderBagId;
                    orderInfo.OrderName = order.BagName;
                    orderInfo.OrderPriority = order.Priority;
                    orderInfo.OrderRemark = order.Remark;
                    orderInfo.OrderTime = order.OrderTime;
                    orderInfo.PreCompleteTime = order.CompleteTime;
                    orderInfo.ShopName = order.Shop.shopName;
                }
                return orderInfo;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        #endregion

        /// <summary>
        /// PHJ---2009-7-31日加
        /// 检查照片的数据库尺寸和相片本身的实际尺寸是否相符        
        /// </summary>
        /// <param name="photoId"></param>
        /// <returns></returns>        
        public bool CheckPicSize(int photoId)
        {
            photoInfo pi = PhotoInfoDAL.GetOneById(photoId);
            if (pi == null)
            {
                return false;
            }
            else
            {
                RasterCodecs.Startup();
                RasterCodecs codecs = new RasterCodecs();
                CodecsImageInfo img = null;
                try
                {
                    //img = codecs.Load(pi.picPath);
                    img = codecs.GetInformation(pi.picPath, true);
                    if (img.Width == pi.pixWidth && img.Height == pi.pixHeight)
                    {
                        return true;
                    }
                    else
                    {
                        return false;
                    }
                }
                catch (RasterException ex)
                {
                    throw ex;
                }
                finally
                {
                    //img.Dispose();
                    RasterCodecs.Shutdown();
                }
            }
        }

        public bool CheckPicSize(photoInfo pi)
        {
            RasterCodecs.Startup();
            RasterCodecs codecs = new RasterCodecs();
            CodecsImageInfo img = null;
            try
            {
                //img = codecs.Load(pi.picPath);
                img = codecs.GetInformation(pi.picPath, true);
                if (img.Width == pi.pixWidth && img.Height == pi.pixHeight)
                {
                    return true;
                }
                else
                {
                    return false;
                }
            }
            catch (RasterException ex)
            {
                throw ex;
            }
            finally
            {
                //img.Dispose();
                RasterCodecs.Shutdown();
            }
        }

        //-------------------------------------------------
        //---------------自动分配照片-----------------------
        /// <summary>
        /// 设置打印机属性
        /// </summary>
        public void SetPrinterAttribute(int printerId, double length, double width, double speed, int dpi, bool disable)
        {
            try
            {
                DDAL.SetPrinterAttribute(printerId, length, width, speed, dpi, disable);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        private Timer timeDistribute = new Timer();
        private bool EnableAutoDistribute=false;
        private int CurrentTechid = 0;
        private int CurrentUserId = 0;

        public event ShowMessage DistributePrinter;
        public DataTable AutoDistributePrinter()
         {
            
             int intUndisphotoStatus = (int) PhotoStatus.NoDistributePrinter;
             int intDisphotoStatus = (int) PhotoStatus.DistributedPrinter;
             int intOrderinfostatus = (int) OrderInfoStatus.Doing;
             int intRtnCount = 0;
             DataTable table = DDAL.AutoDistributePrinter(intUndisphotoStatus, intOrderinfostatus, CurrentTechid, intDisphotoStatus, CurrentUserId,
                                        out intRtnCount);
             return table;

         }
        public void StartAutoDistribute(int inTechid, int inUserid,int inTimeSpan)
        {
            CurrentTechid = inTechid;
            CurrentUserId = inUserid;
            timeDistribute.Enabled = true;
            EnableAutoDistribute = true;
            timeDistribute.Interval = inTimeSpan;
            timeDistribute_Elapsed(null,null);
        }
        public void EndAutoDistribute()
        {
            timeDistribute.Enabled = false;
            EnableAutoDistribute = false;
        }

        void timeDistribute_Elapsed(object sender, ElapsedEventArgs e)
        {
            try
            {

            timeDistribute.Enabled = false;
            int intUndisphotoStatus = (int)PhotoStatus.NoDistributePrinter;
            int intDisphotoStatus = (int)PhotoStatus.DistributedPrinter;
            int intOrderinfostatus = (int)OrderInfoStatus.Doing;
            int intRtnCount = 0;
            DataTable table = DDAL.AutoDistributePrinter(intUndisphotoStatus, intOrderinfostatus, CurrentTechid, intDisphotoStatus, CurrentUserId,
                                       out intRtnCount);
            DistributePrinter(table, intRtnCount);//触发返回事件
            }
            catch (Exception exx)
            {

                
            }
            finally
            {
                if (EnableAutoDistribute)
                {
                    timeDistribute.Enabled = true;
                }
                else
                {
                    timeDistribute.Enabled = false;
                }
            }

        }
        #region 获取打印机现有的任务量
        /// <summary>
        /// 获取打印机现有的任务量
        /// </summary>
        /// <param name="printerId"></param>
        /// <returns></returns>
        public double GetTask(int printerId)
        {
            try
            {
                return DDAL.GetTask(printerId);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public List<string> CheckPrinter()
        {
            List<string> rtnStringList=new List<string>();
            using (newSampleYPDBEntities db=new newSampleYPDBEntities())
            {
                List<printer> listPrinter = db.printer.ToList();
                foreach (printer pr in listPrinter)
                {
                    if(pr.MaxHeight==pr.MinHeight||pr.MinWidth==pr.MaxWidth)
                    {
                        rtnStringList.Add(pr.PName);
                    }
                }
            }
            return rtnStringList;
        }

        #endregion

        #region 数据结构


        #endregion


    }
}
